home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 2: Applications / Linux Cubed Series 2 - Applications.iso / circuits / irsim-ca.2 / irsim-ca / irsim-cap-9.2 / src / ana11 / coords.c < prev    next >
C/C++ Source or Header  |  1993-01-15  |  8KB  |  329 lines

  1. /*
  2.  *     ********************************************************************* 
  3.  *     * Copyright (C) 1988, 1990 Stanford University.                     * 
  4.  *     * Permission to use, copy, modify, and distribute this              * 
  5.  *     * software and its documentation for any purpose and without        * 
  6.  *     * fee is hereby granted, provided that the above copyright          * 
  7.  *     * notice appear in all copies.  Stanford University                 * 
  8.  *     * makes no representations about the suitability of this            * 
  9.  *     * software for any purpose.  It is provided "as is" without         * 
  10.  *     * express or implied warranty.  Export of this software outside     * 
  11.  *     * of the United States of America may require an export license.    * 
  12.  *     *********************************************************************
  13.  */
  14.  
  15. /*
  16.  * Calculate the Position/bounding-boxes of all the objects on the screen.
  17.  */
  18. #include "ana.h"
  19. #include "ana_glob.h"
  20.  
  21.  
  22. #define    TRACEGAP    4            /* separation between traces */
  23. #define    MAX_INCR    ( 3*CHARWIDTH+TRACEGAP )   /* max. height of a trace */
  24. #define    MINWIDTH    ( 14 * CHARWIDTH )       /* minimum traces width */
  25. #define    MINHEIGHT    (7 * CHARHEIGHT)
  26. #define    BOX_SIZE    13            /* size of banner icons */
  27.  
  28.  
  29.         /* this is the same as traceBox.bot - traceBox.top + 1 */
  30. #define TracesHeight() ( YWINDOWSIZE - SCROLLBARHEIGHT - 2 * CHARHEIGHT - 4 - \
  31.   max( CHARHEIGHT + 3, BOX_SIZE + 6 - 1 ) )
  32.  
  33.  
  34. public    int     XWINDOWSIZE = 0;
  35. public    int     YWINDOWSIZE = 0;
  36.  
  37. public    BBox    traceBox;
  38. public    BBox    bannerBox;
  39. public    BBox    scrollBox;
  40. public    BBox    barPos;
  41. public    BBox    namesBox;
  42. public    BBox    cursorBox;
  43. public    BBox    timesBox;
  44. public    BBox    textBox;
  45. public    BBox    iconBox;
  46. public    BBox    sizeBox;
  47. public    BBox    selectBox;
  48. public    BBox    menuBox;
  49.  
  50. private    int     tw_left = 0;
  51. private    int     tw_right = 0;
  52.  
  53. /*
  54.  * Set the Bounding Box/Location of all the objects in the analyzer window.
  55.  */
  56. private void SetWindowCoords()
  57.   {
  58.     bannerBox.left = 0;
  59.     bannerBox.top = 0;
  60.     bannerBox.bot = max( bannerBox.top + CHARHEIGHT + 3, (BOX_SIZE + 6 - 1) );
  61.     bannerBox.right = XWINDOWSIZE - 1;
  62.  
  63.     iconBox.top = bannerBox.top + 2;
  64.     iconBox.bot = iconBox.top + BOX_SIZE - 1;
  65.     iconBox.left = 2;
  66.     iconBox.right = iconBox.left + BOX_SIZE - 1;
  67.  
  68.     sizeBox.top = iconBox.top;
  69.     sizeBox.bot = iconBox.top;
  70.     sizeBox.right = XWINDOWSIZE - 4;
  71.     sizeBox.left = sizeBox.right - (BOX_SIZE - 1);
  72.  
  73.       {
  74.     register Menu  *mp;
  75.     Coord          x, x1;
  76.  
  77.         menuBox.bot = bannerBox.bot - 2;
  78.         menuBox.top = menuBox.bot - CHARHEIGHT;
  79.     for( mp = menu; mp->str != NULL; mp++ );
  80.  
  81.     menuBox.right = sizeBox.left - 3;
  82.     for( mp--, x = menuBox.right + 1 ; mp >= menu; mp-- )
  83.       {
  84.         mp->box.top = menuBox.top;
  85.         mp->box.bot = menuBox.bot;
  86.         mp->box.right = x - 1;
  87.         mp->box.left = x - CHARWIDTH * (mp->len + 1);
  88.         x = mp->box.left - 3;
  89.       }
  90.     menuBox.left = x + 1;
  91.     selectBox.right = x - 4;
  92.       }
  93.     
  94.     selectBox.top = iconBox.top;
  95.     selectBox.bot = iconBox.bot;
  96.     selectBox.left = iconBox.right + bannerLen * CHARWIDTH + 4 + 3;
  97.  
  98.     timesBox.left = tw_left - 1;
  99.     timesBox.top = bannerBox.bot + 1;
  100.     timesBox.right = tw_right + 1;
  101.     timesBox.bot = timesBox.top + CHARHEIGHT + 2 - 1;
  102.  
  103.     textBox.left = 0;
  104.     textBox.top = YWINDOWSIZE - CHARHEIGHT - 3;
  105.     textBox.right = XWINDOWSIZE - 1;
  106.     textBox.bot = YWINDOWSIZE - 1;
  107.  
  108.     namesBox.left = 0;
  109.     namesBox.top = timesBox.bot + 1;
  110.     namesBox.right = tw_left - 1;
  111.     namesBox.bot = textBox.top - SCROLLBARHEIGHT;
  112.  
  113.     cursorBox.top = namesBox.top;
  114.     cursorBox.right = XWINDOWSIZE - 1;
  115.     cursorBox.left = tw_right + 1;
  116.     cursorBox.bot = namesBox.bot;
  117.  
  118.     traceBox.left = tw_left;
  119.     traceBox.bot = namesBox.bot + 1;
  120.     traceBox.right = tw_right;
  121.     traceBox.top = namesBox.top;
  122.  
  123.     scrollBox.left = traceBox.left - ARROW_WIDTH + 1;
  124.     scrollBox.bot = textBox.top;
  125.     scrollBox.right = traceBox.right + ARROW_WIDTH;
  126.     scrollBox.top = scrollBox.bot - SCROLLBARHEIGHT + 1;
  127.  
  128.     barPos.bot = scrollBox.bot - (SCROLLBARHEIGHT / 2) + 2;
  129.     barPos.top = barPos.bot - 7;
  130.   }
  131.  
  132.                     /* char + 2 spaces + 2 lines */
  133. #define    MINBUSHEIGHT        ( CHARHEIGHT + 4 + TRACEGAP )
  134.                     /* a bit smaller that a char */
  135. #define    MINSIGHEIGHT        ( CHARHEIGHT + TRACEGAP - 3 )
  136.  
  137. /*
  138.  * Calculate the number of traces that will fit (vertically).
  139.  */
  140. private int VisibleTraces()
  141.   {
  142.     register Trptr  t;
  143.     register int    Ysize, n, i, busHeight, logicHeight;
  144.  
  145.     Ysize = TracesHeight();
  146.  
  147.     Ysize -= TRACEGAP;
  148.     busHeight = MINBUSHEIGHT;
  149.     logicHeight = MINSIGHEIGHT;
  150.  
  151.     for( i = 0, n = traces.total, t = traces.first; i < n; i++, t = t->next )
  152.       {
  153.     Ysize -= ( IsVector( t ) ) ? busHeight : logicHeight;
  154.     if( Ysize < 0 )
  155.         return( i );
  156.       }
  157.     return( n );
  158.   }
  159.  
  160.  
  161. /*
  162.  * Calculate vertical position of traces.
  163.  */
  164. public void SetSignalPos()
  165.   {
  166.     register Trptr    t;
  167.     register int      i, pos;
  168.     int               busHeight, logicHeight, incr, Ysize;
  169.  
  170.     if( traces.disp == 0 )
  171.     return;
  172.  
  173.     Ysize = TracesHeight();
  174.     pos = TRACEGAP;
  175.     busHeight = MINBUSHEIGHT;
  176.     logicHeight = MINSIGHEIGHT;
  177.  
  178.     for( i = traces.disp, t = traces.first; i != 0 ; i--, t = t->next )
  179.     pos += ( IsVector( t ) ) ? busHeight : logicHeight;
  180.  
  181.     incr = (Ysize - pos) / traces.disp;
  182.     if( incr > MAX_INCR )
  183.     incr = MAX_INCR;
  184.  
  185.     busHeight += (incr - TRACEGAP);
  186.     logicHeight += (incr - TRACEGAP);
  187.  
  188.     pos = traceBox.top + TRACEGAP;
  189.     
  190.     for( t = traces.first, i = traces.disp; i != 0; i--, t = t->next )
  191.       {
  192.         t->top = pos;
  193.     pos += ( IsVector( t ) ) ? busHeight : logicHeight;
  194.         t->bot = pos;
  195.     pos += TRACEGAP;
  196.       }
  197.   }
  198.  
  199.  
  200. /*
  201.  * Return the maximum number of digits required to display a trace value.
  202.  */
  203. private int MaxTraceDigits( n )
  204.   register int  n;
  205.   {
  206.     register int     ndigits, maxDigits;
  207.     register Trptr   t;
  208.     
  209.     maxDigits = 1;
  210.     for( t = traces.first; n != 0; n--, t = t->next )
  211.       {
  212.     if( IsVector( t ) )
  213.       {
  214.         ndigits = (t->n.vec->nbits + t->bdigit - 1) / t->bdigit;
  215.         if( ndigits > maxDigits )
  216.         maxDigits = ndigits;
  217.       }
  218.       }
  219.     return( maxDigits );
  220.   }
  221.  
  222.  
  223. /*
  224.  * Return the length of the longest trace name.
  225.  */
  226. private int MaxTraceName( n )
  227.   register int  n;
  228.   {
  229.     register int      i, len, maxLen;
  230.     register Trptr    t;
  231.     
  232.     maxLen = 0;
  233.     for( t = traces.first; n != 0; n--, t = t->next )
  234.       {
  235.     len = strlen( t->name );
  236.     if( len > maxLen )
  237.         maxLen = len;
  238.       }
  239.     return( maxLen );
  240.   }
  241.  
  242.  
  243. public void GetMinWsize( w, h )
  244.   int  *w, *h;
  245.   {
  246.     int  maxDigits, maxName;
  247.  
  248.     maxDigits = MaxTraceDigits( traces.total );
  249.     maxDigits = max( maxDigits, 16 );
  250.     maxName = MaxTraceName( traces.total );
  251.     maxName = max( maxName, 15 );
  252.  
  253.     *w = max( (CHARWIDTH * maxName) + 2, ARROW_WIDTH + 4 ) + 2 +
  254.      max( (CHARWIDTH * maxDigits) + 2, ARROW_WIDTH ) + 2 + MINWIDTH;
  255.     *h = MINHEIGHT;
  256.   }
  257.  
  258.  
  259. public
  260. #define    NTRACE_CHANGE        0x01    /* # of visible traces changed */
  261. public
  262. #define    WIDTH_CHANGE        0x02    /* change in width of trace window */
  263. public
  264. #define    HEIGHT_CHANGE        0x04    /* change in height of trace window */
  265. public
  266. #define    RESIZED            0x10    /* window is too small,should resize */
  267.  
  268. public int WindowChanges()
  269.   {
  270.     int         left, right, tooSmall;
  271.     int         ndisp, maxDigits, maxName, ret;
  272.     static int  lastY = -1;
  273.  
  274.     ndisp = VisibleTraces();
  275.     maxDigits = MaxTraceDigits( ndisp );
  276.     maxName = MaxTraceName( ndisp );
  277.  
  278.     left = max( (CHARWIDTH * maxName) + 2, ARROW_WIDTH + 4 ) + 2;
  279.     right = XWINDOWSIZE - max( (CHARWIDTH * maxDigits) + 2, ARROW_WIDTH ) - 2;
  280.  
  281.     tooSmall = FALSE;
  282.     if( right - left < MINWIDTH )
  283.     tooSmall = TRUE;
  284.  
  285.     if( YWINDOWSIZE < MINHEIGHT )
  286.     tooSmall = TRUE;
  287.  
  288.     if( tooSmall )
  289.       {
  290.     windowState.tooSmall = TRUE;
  291.     lastY = 0;
  292.     return( RESIZED );
  293.       }
  294.  
  295.     windowState.tooSmall = FALSE;    /* could have been set before */
  296.  
  297.     ret = 0;
  298.     if( ndisp != traces.disp )
  299.       {
  300.     int  last_disp = traces.disp;
  301.  
  302.     traces.disp = ndisp;
  303.     ret |= NTRACE_CHANGE;
  304.     if( ndisp > last_disp )
  305.         UpdateTraceCache( last_disp );
  306.       }
  307.  
  308.     if( (left != tw_left or right != tw_right) )
  309.       {
  310.     tw_left = left;
  311.     tw_right = right;
  312.     ret |= WIDTH_CHANGE;
  313.       }
  314.  
  315.     if( lastY != YWINDOWSIZE )
  316.       {
  317.     lastY = YWINDOWSIZE;
  318.     ret |= HEIGHT_CHANGE;
  319.       }
  320.  
  321.     if( ret & (HEIGHT_CHANGE | WIDTH_CHANGE) )
  322.     SetWindowCoords();
  323.  
  324.     if( ret & (HEIGHT_CHANGE | NTRACE_CHANGE) )
  325.     SetSignalPos();
  326.  
  327.     return( ret );
  328.   }
  329.